package com.jjmmbb.baoSudoku;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import cn.domob.android.ads.DomobAdEventListener;
import cn.domob.android.ads.DomobAdManager.ErrorCode;
import cn.domob.android.ads.DomobAdView;
import cn.domob.android.ads.DomobUpdater;

import com.adb.dao.GameDataManager;
import com.adb.dao.GameDraftManager;
import com.adb.entity.DataRect;
import com.adb.entity.GameData;
import com.adb.entity.GameDraft;
import com.adb.util.GameCheck;
import com.adb.util.ShuDuView;
import com.adb.util.Util;

public class GameActivity extends BaseActivity implements OnClickListener,
		OnCheckedChangeListener {

	public static List<DataRect> rects;

	public static int firstX = 5; // 第一个点的x坐标, 存放表格距离屏幕边缘的宽度
	public static int firstY = 5; // 第一个点的y坐标,
	public static int rectSize = 30;
	public static final int colNum = 9; // 方格的数量

	public static DataRect currentRect;

	public static int currentNumber;

	private GameData currentGameData;

	private final int id_menu_restart = 1201;
	private final int id_menu_show_finish = 1202;
	private final int id_menu_set = 1203;
	private final int id_menu_sound = 1205;
	private final int id_menu_light = 1206;
	private final int id_menu_night = 1207;

	public static ShuDuView gameView;

	public GameCheck gameCheck;

	LinearLayout gameLayout;
	LinearLayout ll_below;
	ScrollView scrollView;
	View belowView;

	Button bt1, bt2, bt3, bt4, bt5, bt6, bt7, bt8, bt9, btX;
	Button bt_help, bt_avInfo;
	ToggleButton bt_light;
	ToggleButton bt_sound;
	TextView tv_time_js, tv_time_best;
	// CheckBox cb_wakelock;

	myTimerTask timerTask = new myTimerTask();
	Timer timer = new Timer(true);

	PowerManager powerManager; // 电源控制管理器，比如防锁屏
	WakeLock mWakeLock; // 唤醒锁

	public static int js; // 游戏计时
	long ad_js = 0; // 单击广告时的计时,用于模拟双击
	String secret = "";

	// sound
	public MediaPlayer soundButton;
	public MediaPlayer soundSelect;

	boolean needMenuIcon = false;

	String[] arrDraft = new String[81];

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		if (null == Comm.currentGameData) {
			gotoActivity(MainActivity.class);
			this.finish();
			return;
		} else {
			currentGameData = Comm.currentGameData;
			// 获取草稿
			GameDraftManager gdm = new GameDraftManager();
			ArrayList<GameDraft> draftList = gdm.getGameDraftListByAVId(this,
					currentGameData.getAv_id());
			for (GameDraft gd : draftList) {
				if (gd.num >= 0 && gd.num < 81) {
					arrDraft[gd.num] = gd.draft;
				}
			}
		}

		iniPer();

		setContentView(R.layout.game);
		gameLayout = (LinearLayout) findViewById(R.id.page);
		// 棋盘
		gameView = (ShuDuView) findViewById(R.id.game_qp);
		gameView.father = this;
		// 棋盘下面部分
		belowView = LayoutInflater.from(this)
				.inflate(R.layout.game_below, null);

		ll_below = (LinearLayout) findViewById(R.id.game_ll_below);
		bt1 = (Button) belowView.findViewById(R.id.game_bt_1);
		bt2 = (Button) belowView.findViewById(R.id.game_bt_2);
		bt3 = (Button) belowView.findViewById(R.id.game_bt_3);
		bt4 = (Button) belowView.findViewById(R.id.game_bt_4);
		bt5 = (Button) belowView.findViewById(R.id.game_bt_5);
		bt6 = (Button) belowView.findViewById(R.id.game_bt_6);
		bt7 = (Button) belowView.findViewById(R.id.game_bt_7);
		bt8 = (Button) belowView.findViewById(R.id.game_bt_8);
		bt9 = (Button) belowView.findViewById(R.id.game_bt_9);
		btX = (Button) belowView.findViewById(R.id.game_bt_X);
		tv_time_js = (TextView) belowView.findViewById(R.id.game_tv_js);
		tv_time_best = (TextView) belowView.findViewById(R.id.game_tv_best);

		bt_light = (ToggleButton) belowView.findViewById(R.id.game_bt_light);
		bt_sound = (ToggleButton) belowView.findViewById(R.id.game_bt_sound);
		bt_help = (Button) belowView.findViewById(R.id.game_bt_help);
		bt_avInfo = (Button) belowView.findViewById(R.id.game_avInfo);

		// 添加游戏的下半部分
		gameLayout.addView(belowView);

		// 添加监听
		bt1.setOnClickListener(this);
		bt2.setOnClickListener(this);
		bt3.setOnClickListener(this);
		bt4.setOnClickListener(this);
		bt5.setOnClickListener(this);
		bt6.setOnClickListener(this);
		bt7.setOnClickListener(this);
		bt8.setOnClickListener(this);
		bt9.setOnClickListener(this);
		btX.setOnClickListener(this);
		bt_light.setOnCheckedChangeListener(this);
		bt_sound.setOnCheckedChangeListener(this);
		bt_avInfo.setOnClickListener(this);
		bt_help.setOnClickListener(this);

		ini();
		if (Comm.isBuy || Comm.currentGameData.isFinish()) {
		} else {
			addAD(true);
		}

		if (Comm.screenHeight <= 800) {
			bt_light.setVisibility(View.GONE); // 小米版
			bt_sound.setVisibility(View.GONE);// 小米版
			bt_help.setVisibility(View.GONE);// 小米版
			bt_avInfo.setVisibility(View.GONE);// 小米版
			needMenuIcon = true;
		}

		setNightMode();
	}

	@Override
	protected void setNightMode() {
		try {
			if (Comm.isNight) {
				gameLayout.setBackgroundResource(R.color.bg_night);
			} else {
				gameLayout.setBackgroundResource(R.color.bg_game);
			}
		} catch (Exception ex) {
			// 找不到id
		}
	}

	// 首先初始化的部分,只做数据初始化
	public void iniPer() {
		loadSound(); // 加载音效

		js = currentGameData.getTime_keeping();

		rectSize = (Comm.screenWidth - firstX * 2 + 1) / colNum;
		rects = new ArrayList<DataRect>();

		String data_initial = currentGameData.getData_initial(); // 原始数据
		String data_ing = currentGameData.getData_ing(); // 进行中的数据

		if (null == data_initial || "" == data_initial
				|| data_initial.length() != 81) {
			data_initial = "";
		}

		if (null == data_ing || "" == data_ing || data_ing.length() != 81) {
			data_ing = data_initial;
		}

		// 补齐81位
		for (int i = data_initial.length(); i < 81; i++) {
			data_initial += "0";
		}
		// 补齐81位
		for (int i = data_ing.length(); i < 81; i++) {
			data_ing += "0";
		}
		// 校验,不是包含0-9的数据为脏数据
		for (int i = 0; i < data_initial.length(); i++) {
			char c = data_initial.charAt(i);
			if ('0' > c || '9' < c) {
				data_initial = "";
				break;
			}
		}
		// 校验,不是包含0-9的数据为脏数据,重置为原始数据
		for (int i = 0; i < data_ing.length(); i++) {
			char c = data_ing.charAt(i);
			if ('0' > c || '9' < c) {
				data_ing = data_initial;
				break;
			}
		}
		// 初始化棋盘
		for (int i = 0; i < 9; i++) { // 行号 对应y值
			for (int j = 0; j < 9; j++) { // 列号 对应x值
				int y = firstY + i * rectSize;
				int x = firstX + j * rectSize;
				int k = i * 9 + j;
				if ('0' == data_initial.charAt(k)) {
					int iniType = 2; // 这里判断为用户下的棋
					rects.add(new DataRect(x, y, rectSize, k, Integer
							.parseInt(data_ing.charAt(k) + ""), iniType,
							arrDraft[k]));
				} else {
					int iniType = 1; // 这里判断为原始棋谱
					rects.add(new DataRect(x, y, rectSize, k, Integer
							.parseInt(data_initial.charAt(k) + ""), iniType));
				}
			}
		}
		if (null != gameView) {
			reflashGameView();
		}
	}

	public void ini() {
		// 处理屏幕防止锁屏
		powerManager = (PowerManager) getSystemService(POWER_SERVICE);
		mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK,
				getClass().getName());

		// 检查数独数据
		gameCheck = new GameCheck(this);

		// 显示关卡名
		bt_avInfo.setText(currentGameData.getAv_id() + ""); // 显示空

		// 计时
		tv_time_js.setText(getStr(R.string.game_timer) + "0:00");

		int best = currentGameData.getTime_best();
		tv_time_best.setText(getStr(R.string.game_bestTime)
				+ Util.secondFormat(best));

		// 功能按钮状态
		bt_light.setChecked(Comm.isWakeLock);
		if (Comm.isWakeLock) {
			mwl_acquire(); // 恢复时保存屏幕唤醒
		}
		bt_sound.setChecked(Comm.isSound);

		// 开启计时线程
		timer.schedule(timerTask, 0, 1000);// 开始计时
	}

	@Override
	protected void onResume() {
		super.onResume();
		if (Comm.isWakeLock) {
			mwl_acquire(); // 恢复时保存屏幕唤醒
		}
		timerTask.beginJS();

		if (null == gameView) {
			this.finish();
		}
	}

	/**
	 * 保持屏幕唤醒
	 */
	public void mwl_acquire() {
		if (null == mWakeLock)
			return;
		if (!mWakeLock.isHeld()) {
			mWakeLock.acquire();
		}
	}

	/**
	 * 取消屏幕唤醒
	 */
	public void mwl_release() {
		if (null == mWakeLock)
			return;
		if (mWakeLock.isHeld()) {
			mWakeLock.release();
		}
	}

	@Override
	protected void onPause() {
		super.onPause();
		saveGame();
		mwl_release();
		timerTask.PauseJS();
	}

	public void loadSound() {
		soundButton = MediaPlayer.create(this, R.raw.button);
		soundSelect = MediaPlayer.create(this, R.raw.select);
	}

	private class myTimerTask extends TimerTask {
		private boolean isJS = true;

		@Override
		public void run() {
			if (isJS) {
				Message message = new Message();
				message.what = 2;
				myHandler.sendMessage(message);
			} else {

			}
		}

		public void beginJS() {
			isJS = true;
		}

		public void PauseJS() {
			isJS = false;
		}
	}

	Handler myHandler = new Handler() {
		// 接收到消息后处理
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				reflashGameView();
				break;
			case 2:
				js++;
				if (null != tv_time_js) {
					tv_time_js.setText(getStr(R.string.game_timer)
							+ Util.secondFormat(js));
				}
				if (js % 180 == 0) {
					saveGame();
				}
				break;
			}
			super.handleMessage(msg);
		}
	};

	@Override
	public void onClick(View v) {
		onClickMethod(v);
		reflashGameView();
	}

	public void reflashGameView() {
		checkAndOther();
		gameView.invalidate();
	}

	public void onClickMethod(View v) {
		switch (v.getId()) {
		case R.id.game_bt_help:
			showHelp();
			break;
		case R.id.game_avInfo:
			show_finish();
			break;
		case R.id.game_bt_1:
			onButtonNumberClick(1);
			break;
		case R.id.game_bt_2:
			onButtonNumberClick(2);
			break;
		case R.id.game_bt_3:
			onButtonNumberClick(3);
			break;
		case R.id.game_bt_4:
			onButtonNumberClick(4);
			break;
		case R.id.game_bt_5:
			onButtonNumberClick(5);
			break;
		case R.id.game_bt_6:
			onButtonNumberClick(6);
			break;
		case R.id.game_bt_7:
			onButtonNumberClick(7);
			break;
		case R.id.game_bt_8:
			onButtonNumberClick(8);
			break;
		case R.id.game_bt_9:
			onButtonNumberClick(9);
			break;
		case R.id.game_bt_X:
			onButtonNumberClick(0);
			break;
		}
	}

	public void onButtonNumberClick(int number) {
		playSelect();
		currentNumber = number;
		// 直接通关
		if (js < 10) {
			secret += number;
			Log.d("ga", secret);
			if (secret.equals("13140")) {
				currentGameData.setState(1);
				GameDataManager gdm = new GameDataManager();
				gdm.update(this, currentGameData);
			}
		}

		if (null == currentRect) {
			return; // 如果当前表格不存在,则返回
		}
		if (currentRect.getType() == 5) {
			return;
		}
		currentRect.setData(number);
		currentRect.setType(5); // 填完数字后,设置为非可写状态
		// 校验
		doCheck();
	}

	// 检查,检查冲突并标记,检查是否完成
	public void doCheck() {
		if (gameCheck.checkClash2()) {
			if (gameCheck.checkFinish()) {
				doFinish();
			}
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// 按下键盘上返回按钮
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			// saveGame();
			timerTask.cancel();
			mwl_release();
			currentRect = null; // 删除当前选中的方格
			finish();
			return true;
		} else {
			return false;
		}
	}

	// ------创建OptionsMenu--------------/
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);

		MenuItem item1 = menu.add(0, id_menu_light, 0, R.string.game_light);
		setMenuIcon(item1, Comm.isWakeLock);

		MenuItem item2 = menu.add(0, id_menu_sound, 0, R.string.game_sound);
		setMenuIcon(item2, Comm.isSound);

		menu.add(0, id_menu_restart, 0, R.string.game_again);

		menu.add(0, id_menu_show_finish, 0, Comm.currentGameData.getAv_id()
				+ ""); // 显示ID

		menu.add(0, id_menu_night, 0, R.string.c_night);
		menu.add(0, id_menu_set, 0, R.string.c_help);
		// menu.findItem(MENU_ADD);// 可以设置按钮的背景
		return true;
	}

	void setMenuIcon(MenuItem item, boolean isOn) {
		if (needMenuIcon) {
			if (isOn) {
				item.setIcon(R.drawable.info);
			} else {
				item.setIcon(R.drawable.infoicon);
			}
		}
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case id_menu_restart:
			clearData(); // 重新开始
			break;
		case id_menu_show_finish:
			show_finish();
			break;
		case id_menu_set:
			showHelp();
			break;
		case id_menu_sound:
			soundChange(!Comm.isSound);
			setMenuIcon(item, Comm.isSound);
			break;
		case id_menu_light:
			lightChange(!Comm.isWakeLock);
			setMenuIcon(item, Comm.isWakeLock);
			break;
		case id_menu_night:
			Comm.isNight = !Comm.isNight;
			setNightMode();
			break;
		}
		return super.onOptionsItemSelected(item);
	}

	// 通关后显示女优信息
	private void show_finish() {
		if (1 == currentGameData.getState()) {
			gotoActivity(FinishShowActivity.class);// 查看完成
		} else {
			Toast.makeText(this, R.string.game_nofinish, Toast.LENGTH_SHORT)
					.show();
		}
	}

	// 查看帮助
	private void showHelp() {
		gotoActivity(HelpActivity.class);
	}

	// 重新开始
	public void clearData() {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setMessage(R.string.game_again_sure)
				.setCancelable(false)
				.setPositiveButton(R.string.c_ok,
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {
								currentGameData.setData_ing("");
								currentGameData.setTime_keeping(0);
								iniPer();
							}
						})
				.setNegativeButton(R.string.c_cancel,
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {
								dialog.cancel();
							}
						});
		AlertDialog ad = builder.create();
		ad.show();
	}

	// 通关
	public void doFinish() {
		timerTask.cancel();

		String data_ing = getCurrentDataString();
		// int old_best = currentGameData.getTime_best();

		currentGameData.setData_ing(data_ing);
		currentGameData.setTime_keeping(0);
		currentGameData.setData_finish(data_ing);
		currentGameData.setState(1);

		GameDataManager gdm = new GameDataManager();
		gdm.update(this, currentGameData); // 保存最佳记录

		// String str_best = secondFormat(old_best);
		String str_js = Util.secondFormat(js);
		if (currentGameData.getTime_best() < 0.1
				|| currentGameData.getTime_best() > js) { // 是否破记录
			currentGameData.setTime_best(js);
			tv_time_best.setText(getStr(R.string.game_bestTime)
					+ Util.secondFormat(js));
		}

		addAD(false);

		// 显示对话框
		String msg = getStr(R.string.game_finish_tip) + "\n"
				+ getStr(R.string.game_finish_time) + str_js;
		AlertDialog.Builder builder0 = new AlertDialog.Builder(this);
		builder0.setMessage(msg);

		final AlertDialog ad = builder0.create();
		ad.show();

		// 设置异步线程,延时收起popView,收起对话框
		Handler handler = new Handler() {
			public void handleMessage(Message msg) { // handle message
				switch (msg.what) {
				case 1:
					ad.dismiss();
				}
				super.handleMessage(msg);
			}
		};

		Message message = handler.obtainMessage(1);
		handler.sendMessageDelayed(message, 3000); // 发送message,3秒后隐藏提示框
	}

	// 改变播放音效状态
	void soundChange(boolean isChecked) {
		Comm.isSound = isChecked;
		Util.saveConfig2Preferences(this);
		if (isChecked) {
			bt_sound.setBackgroundResource(R.drawable.btn_bg_3);
		} else {
			bt_sound.setBackgroundResource(R.drawable.btn_bg_1);
		}
		bt_sound.setPadding(Util.dip2px(this, 10), 0, Util.dip2px(this, 10), 0);
	}

	// 改变是否常亮状态
	void lightChange(boolean isChecked) {
		Comm.isWakeLock = isChecked;
		Util.saveConfig2Preferences(this);
		if (Comm.isWakeLock) {
			mwl_acquire(); // 恢复时保存屏幕唤醒
			bt_light.setBackgroundResource(R.drawable.btn_bg_3);
		} else {
			mwl_release();
			bt_light.setBackgroundResource(R.drawable.btn_bg_1);
		}
		bt_light.setPadding(Util.dip2px(this, 10), 0, Util.dip2px(this, 10), 0);
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		switch (buttonView.getId()) {
		case R.id.game_bt_sound:
			soundChange(isChecked);
			break;
		case R.id.game_bt_light:
			lightChange(isChecked);
			break;
		}
	}

	// 保存游戏
	private void saveGame() {
		String data_ing = getCurrentDataString();
		currentGameData.setData_ing(data_ing);
		currentGameData.setTime_keeping(js);
		GameDataManager gdm = new GameDataManager();
		gdm.update(this, currentGameData);
	}

	// 选中方格后播放声音
	public void playSelect() {
		if (!Comm.isSound) {
			return;
		}
		try {
			soundSelect.start();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// ----------------------辅助方法----------------------------------------
	// 获取当前棋谱数据的整数,数组
	private int[] getCurrentDataArray() {
		int[] data = new int[81];
		for (DataRect dr : GameActivity.rects) {
			data[dr.getNumber()] = dr.getData();
		}
		return data;
	}

	// 获取当前棋谱数据的字符串形式
	private String getCurrentDataString() {
		int[] data_check = getCurrentDataArray();
		String data_ing = "";
		for (int a : data_check) {
			data_ing += a;
		}
		return data_ing;
	}

	// --填入的某个数字,如果有9个了,就将按钮的字体变灰
	private void checkAndOther() {
		int[] currentData = getCurrentDataArray();
		int[] checkData = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

		for (int i = 0; i < 81; i++) {
			checkData[currentData[i]]++;
		}

		try {
			// 初始化没有完成的时候,按钮式null,这里会报错
			if (checkData[1] >= 9) {
				bt1.setTextColor(Color.GRAY);
			} else {
				bt1.setTextColor(Color.WHITE);
			}
			if (checkData[2] >= 9) {
				bt2.setTextColor(Color.GRAY);
			} else {
				bt2.setTextColor(Color.WHITE);
			}
			if (checkData[3] >= 9) {
				bt3.setTextColor(Color.GRAY);
			} else {
				bt3.setTextColor(Color.WHITE);
			}
			if (checkData[4] >= 9) {
				bt4.setTextColor(Color.GRAY);
			} else {
				bt4.setTextColor(Color.WHITE);
			}
			if (checkData[5] >= 9) {
				bt5.setTextColor(Color.GRAY);
			} else {
				bt5.setTextColor(Color.WHITE);
			}
			if (checkData[6] >= 9) {
				bt6.setTextColor(Color.GRAY);
			} else {
				bt6.setTextColor(Color.WHITE);
			}
			if (checkData[7] >= 9) {
				bt7.setTextColor(Color.GRAY);
			} else {
				bt7.setTextColor(Color.WHITE);
			}
			if (checkData[8] >= 9) {
				bt8.setTextColor(Color.GRAY);
			} else {
				bt8.setTextColor(Color.WHITE);
			}
			if (checkData[9] >= 9) {
				bt9.setTextColor(Color.GRAY);
			} else {
				bt9.setTextColor(Color.WHITE);
			}
		} catch (Exception e) {
			// 初始化没有完成的时候,这里会报错
		}
	}

	// -------------------添加广告---------------------------------------

	RelativeLayout adContainer;

	void addAD(boolean isShow) {
		if (adContainer != null) {
			if (!isShow) {
				// 隐藏广告
				adContainer.setVisibility(View.GONE);
			}
			return;
		}
		adContainer = new RelativeLayout(this);

		// bzSudoku: 56OJyHIYuMiMpHKWmR
		// jxSudoku: 56OJyHIYuNcYUGK4m4
		String PUBLISHER_ID = "56OJyHIYuMiMpHKWmR";

		// 创建一个320x50的广告View
		DomobAdView mAdview320x50;// 广告
		mAdview320x50 = new DomobAdView(this, PUBLISHER_ID,
				DomobAdView.INLINE_SIZE_320X50);
		mAdview320x50.setKeyword("game");
		mAdview320x50.setUserGender("male");
		mAdview320x50.setUserBirthdayStr("2000-08-08");
		mAdview320x50.setUserPostcode("123456");

		// 设置广告view的监听器。
		mAdview320x50.setAdEventListener(new DomobAdEventListener() {

			@Override
			public void onDomobAdReturned(DomobAdView adView) {
			}

			@Override
			public void onDomobAdOverlayPresented(DomobAdView adView) {
			}

			@Override
			public void onDomobAdOverlayDismissed(DomobAdView adView) {
			}

			@Override
			public void onDomobAdClicked(DomobAdView arg0) {

			}

			@Override
			public void onDomobAdFailed(DomobAdView arg0, ErrorCode arg1) {

			}

			@Override
			public void onDomobLeaveApplication(DomobAdView arg0) {
			}
		});

		// 将广告View增加到视图中。
		adContainer.addView(mAdview320x50);

		// 布局
		FrameLayout.LayoutParams lp_bottom = new FrameLayout.LayoutParams(
				FrameLayout.LayoutParams.MATCH_PARENT,
				FrameLayout.LayoutParams.WRAP_CONTENT);

		// 设置广告出现的位置(悬浮于顶部)
		lp_bottom.gravity = Gravity.BOTTOM;
		addContentView(adContainer, lp_bottom);

		// 检查广告更新
		DomobUpdater.checkUpdate(this, PUBLISHER_ID);
	}

}
